<?php

namespace App\Modules\LuckDraw\Models;

use Illuminate\Database\Eloquent\Model;
use phpDocumentor\Reflection\Types\Self_;


class UserPropLogModel extends Model {
    protected $table = "luck_draw_user_prop_log";

    const USER_PROP_TYPE_EXCHANGE = 1000; //钻石兑换道具
    const USER_PROP_TYPE_DRAW = 2000;     //抽奖消耗
    const USER_PROP_TYPE_RECYCLE = 2001;     //回收消耗
    //某些活动赠送道具 占用3001-3999
    const USER_PROP_TYPE_ACT_SMS = 3001;  //短信召回赠送
    const USER_PROP_TYPE_ACT_WORLDCUP = 3002;  //世界杯活动赠送
    const USER_PROP_TYPE_ACT_RECALL_202212 = 3003;  //2022年12月老用户召回活动


    const USER_PROP_TYPE_DESC = [
        //抽奖页面用钻石兑换
        self::USER_PROP_TYPE_EXCHANGE => '钻石兑换',
        //抽奖页面抽奖消耗
        self::USER_PROP_TYPE_DRAW => '抽奖消耗',
        self::USER_PROP_TYPE_RECYCLE => '回收消耗',
        //某些活动赠送道具 占用3001-3999
        self::USER_PROP_TYPE_ACT_SMS => '短信召回赠送',
        self::USER_PROP_TYPE_ACT_WORLDCUP => '世界杯活动赠送',
        self::USER_PROP_TYPE_ACT_RECALL_202212 => '2022年12月老用户召回活动',
    ];

    public static function getDescFromType($type){
        return self::USER_PROP_TYPE_DESC[$type]??'';
    }

    //保存日志
    public function log(int $luckId, int $userId, int $type, int $change):bool{
        if (empty($luckId) || empty($userId) || empty($type)) {
            return false;
        }
        $userPropLogModel = new UserPropLogModel();
        $userPropLogModel->luck_id = $luckId;
        $userPropLogModel->user_id = $userId;
        $userPropLogModel->type = $type;
        $userPropLogModel->change = $change;
        $userPropLogModel->desc = self::getDescFromType($type);

        return $userPropLogModel->save();
    }
}